<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'材料出库订单'),
	array('op'=>'edit','title'=>'新增材料出库'),
);
$return['statuss']=$this->ruku_status;
$return['paytype']=get_pay_types();
$return['paytype']['peerpay']='找人代付';
$return['paytype']['offpay']='线下收款';
$return['paytype']['offsao']='线下扫码';
$return['ispay']=array('0'=>'未支付_No pay','1'=>'已支付_Is pay');
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['type']=$_RQ['type'];
	$return['params']['type']=$_RQ['type'];
	$_SESSION['type']=$_RQ['type'];
	if(!empty($_RQ['ordersn'])){
		$params['ordersn']=$_RQ['ordersn'];
		$return['params']['ordersn']=$_RQ['ordersn'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_erp_chukugoods',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$goodsinfo=pdo_get('jy_weishop_goods',array('id'=>$item['goodsid']),array('title','image','unit'));
			$item['total']=$goods['total'];
			$item['title']=$goodsinfo['title'];
			$item['image']=$goodsinfo['image'];
			$item['unit']=$goodsinfo['unit'];
			
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'image','title'=>'商品图片','type'=>'image'),
			array('name'=>'title','title'=>'商品名称','type'=>'string'),
			array('name'=>'total','title'=>'数量','type'=>'string'),
			array('name'=>'unit','title'=>'单位','type'=>'string'),
			array('name'=>'price','title'=>'成本价','type'=>'string'),
			array('name'=>'total_price','title'=>'成本金额','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'status','width'=>10,'title'=>'订单状态','type'=>'radio','options'=>'status'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		$data=array(
			'groupid'=>trim($post['groupid']),
			'group2id'=>trim($post['group2id']),
			'unit'=>trim($post['unit']),
			'total'=>trim($post['total']),
			'price'=>trim($post['price']),
			'goodsid'=>trim($post['goodsid']),
			'remark'=>trim($post['remark']),
		);
		if(!$id){
			$data['uniacid']=$_SESSION['uniacid'];
			$data['type']=$_SESSION['type'];
			$data['createtime']=time();
			pdo_insert('jy_erp_chukugoods',$data);
		}else{
			pdo_update('jy_erp_chukugoods',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
		exi('操作成功！','','list');
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_erp_chukugoods',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'desc'=>'入库单',
		'edit'=>array(
			array('title'=>'这里《出库单》','type'=>'tip'),
			array('type'=>'select2_line','name'=>'groupid','options'=>'groups','title'=>'选择部门',
				'name2'=>'group2id','options2'=>'groups2','title2'=>'选择职位',
			),
			array('type'=>'choose','title'=>'选择商品','name'=>'goodsid','action'=>'jy_weishop/goods.get_goods/','choose_title'=>'选择商品'),
			array('name'=>'total','title'=>'数量','type'=>'string'),
			array('name'=>'unit','title'=>'单位','type'=>'string'),
			array('name'=>'price','title'=>'成本价','type'=>'string'),
			array('name'=>'remark','title'=>'备注','type'=>'text'),
		)
	);
	$user_juese=$this->user_juese;
	$return['groups']=array();
	foreach($user_juese as $key=>$title){
		$return['groups'][$key]=array('id'=>$key,'title'=>$title);
		$pv['groups2']=pdo_getall('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'juese'=>$key),array('title','id'),'id');
	}
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_erp_chukugoods',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
